package org.vectrics.client.webclient;

import org.apache.log4j.*;


public class HttpRequestThread extends CommunicationThread {
	private int sleepTime = 1000;
	private boolean stopped = false;
   // private String serverAddress = "";
	private String computerFriendlyName = null;
	private int requestCount = 0;
	private boolean testRequested = true;
	private boolean paused = false;
	private boolean running = false;
	private HttpRequester httpRequest = null;
    
	private transient static Logger log = Logger.getLogger(HttpRequestThread.class);

	public HttpRequestThread(ServiceConnection connection) {
		super(connection);
		this.setName(this.getClass().getName());
		httpRequest = new HttpRequester();
	}
    
    
	public void doConnect(String url) {
		stopped = false;
	}
    
	public void runTests() {
		testRequested = true;
	}
  
	public void terminate() {
		stopped = true;
	}

	public void connect() {
		paused = false;
	}
    
	public void disconnect() {
		paused = true;
		setConnectStatus(ConnectionStatus.DISCONNECTED);
	}
    
	public boolean getIsRunning() {
		return(this.running);
	}
	public void run() {
		int runCount = 0;
		this.running = true;
        
		log.debug("HttpLoggingThread  Starting.");
		while (!stopped) {
			if (paused == false) {
				ServerCommand command = this.getNextCommand();
				if (command != null) {
					try {
						log.info("run() - preparing request");
						allLoggersCounter++;
						loggerLevelCounter++;
						newEventsCounter++;
						oldEventsCounter++;
	
						log.debug("run() - Connection Status = " + getConnectStatus());
						sleep(sleepTime);
					}
					catch (java.lang.InterruptedException ie) {
						log.error("Sleep of PeriodicTask was interupted", ie);
					}
				}
			}
		}
		this.running = false;
		log.info("http communication thread terminated.");
	}

    
    
    



    
}
